<?php
namespace App\Models\Msg;

use Illuminate\Database\Eloquent\Model;

/**
 * 回复 的消息类
 * @author lee
 *
 */
class msgRpM extends Model
{
    public static  $STable="lee_msg_reply";
    protected  $table="lee_msg_reply";
    
    /**
     * 添加 记录
     * @param array $Item 
     * 
     * ['userid'=>1,'berpuserid'=>5,'cmtid'=>3,'rpid'=>4]
     */
    public static function addItem(array $Item){
        $inst=new msgRpM();
        foreach ($Item as $k=>$v){
            $inst->$k=$v;
        }
        $inst->save();
    }
    
    /**
     * 删除 回复 信息
     * @param array $item ['rpid'=>4]
     */
    public static function dltItem(array $item){
        $item['ispushed']=false;
        self::where($item)->delete();
    }
    
    
    /**
     * 返回未读信息
     * @param unknown $userid
     * @param number $lmt
     * @param number $offset
     */
    static public function getUnreadMsg($userid,$lmt=10,$offset=0){
        return  self::where(['berpuserid'=>$userid,'ispushed'=>false])->select('id','rpid','cmtid','userid')
        ->offset($offset)->limit($lmt)->get();
    }
    
    /**
     * 返回 已读信息
     * @param unknown $userid
     * @param number $lmt
     * @param number $offset
     */
    static  public function getReadMsg($userid,$lmt=10,$offset=0){
        return  self::where(['berpuserid'=>$userid,'ispushed'=>true])->select('id','rpid','cmtid','userid')
        ->offset($offset)->limit($lmt)->get();
    }
    
    /***
     * 返回  用户的  未推送消息个数
     * @param int $userid
     */
    static public function msgCount($userid){
        return self::where(['berpuserid'=>$userid,'ispushed'=>false])->count();
    }
    
    
    /***
     *  标识信息已推送
     * @param  $msgid
     */
    static public function markReaded($msgid){
        self::where('id',$msgid)->update('ispushed',true);
    }
    
    
    
    
}

?>